package com.zhj.threadpoolboot.config;

import cn.hutool.core.lang.Console;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.security.Security;
import java.util.concurrent.ThreadPoolExecutor;
 
/**
 * @Author: ChenBin
 */
@Slf4j
@Component
public class ThreadPoolMonitor extends ThreadPoolTaskExecutor {
 

 
    @Scheduled(cron = "0/1 * * * * ? ")
    private void showThreadPoolInfo() {
        ThreadPoolExecutor threadPoolExecutor = getThreadPoolExecutor();

           /* log.info("{} taskCount [{}], completedTaskCount [{}], activeCount [{}], queueSize [{}]",
                    this.getThreadNamePrefix(),
                    threadPoolExecutor.getTaskCount(),
                    threadPoolExecutor.getCompletedTaskCount(),
                    threadPoolExecutor.getActiveCount(),
                    threadPoolExecutor.getQueue().size());*/

        Console.log(" 线程前缀：{},总任务：{},活跃线程数量：{},完成任务数：{},队列大小：{}" ,getThreadNamePrefix(),threadPoolExecutor.getTaskCount(),threadPoolExecutor.getActiveCount(), threadPoolExecutor.getCompletedTaskCount(), threadPoolExecutor.getQueue().size());


    }
}